package stkr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Stkr {

	{

		try {
			FileHandler hand = new FileHandler(StkrConstants.loggerFile);
			Logger.getLogger(StkrConstants.loggerFile).setLevel(Level.ALL);
			Logger.getLogger(StkrConstants.loggerFile).addHandler(hand);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	private String tickerName;
	private ArrayList<Stock> tickerStocks;

	public String getTickerName() {
		return tickerName;
	}

	public ArrayList<Stock> getTickerStocks() {
		return tickerStocks;
	}

	public Stkr(String tickerName) {
		this.tickerName = tickerName;
	}

	public void startTicker() throws SecurityException, IOException {
		loadSavedTicker();
		for (Stock stock : tickerStocks) {
			Thread t = new Thread(new StockThread(stock,
					StkrConstants.stockUpdateInterval));
			t.start();
		}
	}

	private void loadSavedTicker() {
		tickerStocks = new ArrayList<Stock>();
		Stock subex = new Stock("532348", "BOM");
		tickerStocks.add(subex);
		Stock goog = new Stock("GOOG", "NASDAQ");
		tickerStocks.add(goog);
		Stock subnse = new Stock("SUBEX", "NSE");
		tickerStocks.add(subnse);
	}

}
